var selectedLabGroupIdSec1 = 0;
function loadLabGroup(mess) {
	$.ajax({
		type:		"GET",
		url:		"../LabAdmin/LoadLabGroup?set_ajax_view",
		dataType:   "json",		
		success: 	function(data) {
		
				if (data.error.code ==  'OK') {
					$('#labTabContent').html(data.result);
					setSelectedLabGroupSec1();	
					showMessage('statusMessage', mess, 'success');
				} else {
					displayError(data.error.mess);				
				}

			}

	});

}

function setSelectedLabGroupSec1() {
	$('#labGroupSelect :option').each(function() {
		if ($(this).val() == selectedLabGroupIdSec1) {
			$(this).attr('selected', 'selected');
			$('#labGroupName').val($(this).html());
			$('#labGroupNameGroupId').val($(this).val());
			if ($('#labGroupNameGroupId').val() != '') {
	            $('#labGroupNameUpdate').attr('disabled',false);
	        } else {
	        	$('#labGroupNameUpdate').attr('disabled','disabled');
	        }
		} else {
			$(this).attr('selected', false);
		}
		
	});
	
}

function saveLabGroupSec1( id, text) {
	if ($.trim(text) == '') {
		showMessage('statusMessage',_('Please enter laboratory group name'), 'error');
		return;
	} else {
		showMessage('statusMessage', '', 'success');
	}
	
	$.ajax({
		type:		"POST",
		url:		"../LabAdmin/SaveLabGroup?set_ajax_view",
		data : 'labGroupId=' + id + '&labGroupText=' + text,
		dataType:   "json",		
		success: 	function(data) {		
				if (data.error.code ==  'OK') {		
					selectedLabGroupIdSec1 = data.result;
					loadLabGroup(_('Save successful'));					
				} else {
					displayError(data.error.mess);				
				}

			}

	});
	
}
